{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "tY_UaVjg5vtc",
    "outputId": "b5bd9680-2f5e-41c8-b5c5-95cef4663518"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import os\n",
    "\n",
    "from keras.models import Sequential, Model\n",
    "from keras.layers import Dense, Dropout, Flatten, Input, MaxPooling1D, Convolution1D, Embedding\n",
    "from keras.layers.merge import Concatenate\n",
    "from keras.datasets import imdb\n",
    "from keras.preprocessing import sequence\n",
    "\n",
    "import re\n",
    "import itertools\n",
    "from collections import Counter\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "np.random.seed(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "djzcmbGPFWnr"
   },
   "outputs": [],
   "source": [
    "def clean_Up(string):\n",
    "    \"\"\"\n",
    "    Tokenization/string cleaning for all datasets except for SST.\n",
    "    Original taken from https://github.com/yoonkim/CNN_sentence/blob/master/process_data.py\n",
    "    \"\"\"\n",
    "    string = re.sub(r\"[^A-Za-z0-9(),!?\\'\\`]\", \" \", string)\n",
    "    string = re.sub(r\"\\'s\", \" \\'s\", string)\n",
    "    string = re.sub(r\"\\'ve\", \" \\'ve\", string)\n",
    "    string = re.sub(r\"n\\'t\", \" n\\'t\", string)\n",
    "    string = re.sub(r\"\\'re\", \" \\'re\", string)\n",
    "    string = re.sub(r\"\\'d\", \" \\'d\", string)\n",
    "    string = re.sub(r\"\\'ll\", \" \\'ll\", string)\n",
    "    string = re.sub(r\",\", \" , \", string)\n",
    "    string = re.sub(r\"!\", \" ! \", string)\n",
    "    string = re.sub(r\"\\(\", \" \\( \", string)\n",
    "    string = re.sub(r\"\\)\", \" \\) \", string)\n",
    "    string = re.sub(r\"\\?\", \" \\? \", string)\n",
    "    string = re.sub(r\"\\s{2,}\", \" \", string)\n",
    "    return string.strip().lower()\n",
    "\n",
    "\n",
    "def load_data():\n",
    "    # Load data from files\n",
    "    positive_examples = list(open(\"./rt-polarity.pos\", encoding='latin-1').readlines())\n",
    "    positive_examples = [s.strip() for s in positive_examples]\n",
    "    negative_examples = list(open(\"./rt-polarity.neg\", encoding='latin-1').readlines())\n",
    "    negative_examples = [s.strip() for s in negative_examples]\n",
    "    # Split by words\n",
    "    x_text = positive_examples + negative_examples\n",
    "    x_text = [clean_Up(sent) for sent in x_text]\n",
    "    x_text = [s.split(\" \") for s in x_text]\n",
    "    # Generate labels\n",
    "    positive_labels = [[0, 1] for _ in positive_examples]\n",
    "    negative_labels = [[1, 0] for _ in negative_examples]\n",
    "    y = np.concatenate([positive_labels, negative_labels], 0)\n",
    "    return [x_text, y]\n",
    "\n",
    "\n",
    "def pad_sentences(sentences, padding_word=\"<PAD/>\"):\n",
    "    # pad sentences to the longest sentence's size\n",
    "    sequence_length = max(len(x) for x in sentences)\n",
    "    padded_sentences = []\n",
    "    for i in range(0,len(sentences)):\n",
    "        sentence = sentences[i]\n",
    "        num_padding = sequence_length - len(sentence)\n",
    "        new_sentence = sentence + [padding_word] * num_padding\n",
    "        padded_sentences.append(new_sentence)\n",
    "    return padded_sentences\n",
    "\n",
    "\n",
    "def build_vocab(sentences):\n",
    "    # Build vocabulary\n",
    "    word_counts = Counter(itertools.chain(*sentences))\n",
    "    # Mapping from index to word\n",
    "    vocabulary_inv = [x[0] for x in word_counts.most_common()]\n",
    "    # Mapping from word to index\n",
    "    vocabulary = {x: i for i, x in enumerate(vocabulary_inv)}\n",
    "    return [vocabulary, vocabulary_inv]\n",
    "\n",
    "\n",
    "def build_input_data(sentences, labels, vocabulary):\n",
    "    x = np.array([[vocabulary[word] for word in sentence] for sentence in sentences])\n",
    "    y = np.array(labels)\n",
    "    return [x, y]\n",
    "\n",
    "\n",
    "def load_preprocess_data():\n",
    "    # Load and preprocess data\n",
    "    sentences, labels = load_data()\n",
    "    sentences_padded = pad_sentences(sentences)\n",
    "    vocabulary, vocabulary_inv = build_vocab(sentences_padded)\n",
    "    x, y = build_input_data(sentences_padded, labels, vocabulary)\n",
    "    return [x, y, vocabulary, vocabulary_inv]\n",
    "\n",
    "\n",
    "def batch_iter(data, batch_size, num_epochs):\n",
    "    data = np.array(data)\n",
    "    data_size = len(data)\n",
    "    num_batches_per_epoch = int(len(data) / batch_size) + 1\n",
    "    for epoch in range(num_epochs):\n",
    "        # Shuffle the data at each epoch\n",
    "        shuffle_indices = np.random.permutation(np.arange(data_size))\n",
    "        shuffled_data = data[shuffle_indices]\n",
    "        for batch_num in range(0,num_batches_per_epoch):\n",
    "            start_index = batch_num * batch_size\n",
    "            end_index = min((batch_num + 1) * batch_size, data_size)\n",
    "            yield shuffled_data[start_index:end_index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "H9rcV4VQ6ImL"
   },
   "outputs": [],
   "source": [
    "# Model Hyperparameters\n",
    "embedding_dim = 50\n",
    "filter_sizes = (3,4,5)\n",
    "num_filters = 10\n",
    "dropout_prob = (0.5, 0.8)\n",
    "hidden_dims = 50\n",
    "\n",
    "# Training parameters\n",
    "batch_size = 50\n",
    "num_epochs = 100\n",
    "\n",
    "# Prepossessing parameters\n",
    "sequence_length = 400\n",
    "max_words = 5000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "_8tf7UZj6Iso"
   },
   "outputs": [],
   "source": [
    "def process_data(data_source):\n",
    "    x, y, vocabulary, vocabulary_inv_list = load_preprocess_data()\n",
    "    vocabulary_inv = {key: value for key, value in enumerate(vocabulary_inv_list)}\n",
    "    y = y.argmax(axis=1)\n",
    "\n",
    "    # Shuffle data\n",
    "    shuffle_indices = np.random.permutation(np.arange(len(y)))\n",
    "    x = x[shuffle_indices]\n",
    "    y = y[shuffle_indices]\n",
    "    train_len = int(len(x) * 0.8)\n",
    "    x_train = x[:train_len]\n",
    "    y_train = y[:train_len]\n",
    "    x_test = x[train_len:]\n",
    "    y_test = y[train_len:]\n",
    "\n",
    "    return x_train, y_train, x_test, y_test, vocabulary_inv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 125
    },
    "colab_type": "code",
    "id": "atAfwQrt6Iz3",
    "outputId": "f083d92d-d726-4b87-8d2c-28766b4a2861"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Load data...\n",
      "Adjusting sequence length for actual size\n",
      "x_train shape: (9595, 56)\n",
      "x_test shape: (1067, 56)\n",
      "Vocabulary Size: 18766\n",
      "Model type is CNN-rand\n"
     ]
    }
   ],
   "source": [
    "# Data Preparation\n",
    "print(\"Load data...\")\n",
    "x_train, y_train, x_test, y_test, vocabulary_inv = process_data(data_source)\n",
    "\n",
    "if sequence_length != x_test.shape[1]:\n",
    "    print(\"Adjusting sequence length for actual size\")\n",
    "    sequence_length = x_test.shape[1]\n",
    "\n",
    "print(\"x_train shape:\", x_train.shape)\n",
    "print(\"x_test shape:\", x_test.shape)\n",
    "print(\"Vocabulary Size: {:d}\".format(len(vocabulary_inv)))\n",
    "\n",
    "embedding_weights = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Ixxpb2WX6VSZ"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From C:\\Users\\Meng\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "WARNING:tensorflow:From C:\\Users\\Meng\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n"
     ]
    }
   ],
   "source": [
    "input_shape = (sequence_length,)\n",
    "\n",
    "model_input = Input(shape=input_shape)\n",
    "\n",
    "z = Embedding(len(vocabulary_inv), embedding_dim, input_length=sequence_length, name=\"embedding\")(model_input)\n",
    "\n",
    "z = Dropout(dropout_prob[0])(z)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "78Y-YICh6VUy"
   },
   "outputs": [],
   "source": [
    "# Convolutional block\n",
    "conv_blocks = []\n",
    "for sz in filter_sizes:\n",
    "    conv = Convolution1D(filters=num_filters,\n",
    "                         kernel_size=sz,\n",
    "                         padding=\"valid\",\n",
    "                         activation=\"relu\",\n",
    "                         strides=1)(z)\n",
    "    conv = MaxPooling1D(pool_size=2)(conv)\n",
    "    conv = Flatten()(conv)\n",
    "    conv_blocks.append(conv)\n",
    "z = Concatenate()(conv_blocks) if len(conv_blocks) > 1 else conv_blocks[0]\n",
    "\n",
    "z = Dropout(dropout_prob[1])(z)\n",
    "z = Dense(hidden_dims, activation=\"relu\")(z)\n",
    "model_output = Dense(1, activation=\"sigmoid\")(z)\n",
    "\n",
    "step = tf.Variable(0, trainable=False)\n",
    "rate = tf.train.exponential_decay(0.00005, step, 10000, 0.95)\n",
    "opt = tf.train.AdamOptimizer(rate)\n",
    "\n",
    "model = Model(model_input, model_output)\n",
    "model.compile(loss=\"binary_crossentropy\", optimizer=opt, metrics=[\"accuracy\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "LO9tEhnp6VXK"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 413
    },
    "colab_type": "code",
    "id": "MSt0V4x36VZt",
    "outputId": "5ec0bc1d-7024-4be6-8160-72094fd047a9"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From C:\\Users\\Meng\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.cast instead.\n",
      "Train on 9595 samples, validate on 1067 samples\n",
      "Epoch 1/100\n",
      " - 3s - loss: 0.6949 - acc: 0.4962 - val_loss: 0.6935 - val_acc: 0.5061\n",
      "Epoch 2/100\n",
      " - 2s - loss: 0.6942 - acc: 0.5023 - val_loss: 0.6934 - val_acc: 0.5042\n",
      "Epoch 3/100\n",
      " - 2s - loss: 0.6935 - acc: 0.5124 - val_loss: 0.6934 - val_acc: 0.5052\n",
      "Epoch 4/100\n",
      " - 2s - loss: 0.6935 - acc: 0.5034 - val_loss: 0.6933 - val_acc: 0.5014\n",
      "Epoch 5/100\n",
      " - 2s - loss: 0.6933 - acc: 0.5122 - val_loss: 0.6933 - val_acc: 0.5061\n",
      "Epoch 6/100\n",
      " - 2s - loss: 0.6932 - acc: 0.5087 - val_loss: 0.6933 - val_acc: 0.5080\n",
      "Epoch 7/100\n",
      " - 2s - loss: 0.6927 - acc: 0.5119 - val_loss: 0.6932 - val_acc: 0.5080\n",
      "Epoch 8/100\n",
      " - 2s - loss: 0.6932 - acc: 0.5046 - val_loss: 0.6932 - val_acc: 0.5192\n",
      "Epoch 9/100\n",
      " - 2s - loss: 0.6918 - acc: 0.5192 - val_loss: 0.6931 - val_acc: 0.5023\n",
      "Epoch 10/100\n",
      " - 2s - loss: 0.6920 - acc: 0.5203 - val_loss: 0.6931 - val_acc: 0.5070\n",
      "Epoch 11/100\n",
      " - 2s - loss: 0.6928 - acc: 0.5118 - val_loss: 0.6930 - val_acc: 0.5136\n",
      "Epoch 12/100\n",
      " - 2s - loss: 0.6917 - acc: 0.5244 - val_loss: 0.6930 - val_acc: 0.5183\n",
      "Epoch 13/100\n",
      " - 2s - loss: 0.6909 - acc: 0.5274 - val_loss: 0.6929 - val_acc: 0.5136\n",
      "Epoch 14/100\n",
      " - 2s - loss: 0.6906 - acc: 0.5330 - val_loss: 0.6928 - val_acc: 0.5098\n",
      "Epoch 15/100\n",
      " - 2s - loss: 0.6905 - acc: 0.5340 - val_loss: 0.6927 - val_acc: 0.5173\n",
      "Epoch 16/100\n",
      " - 2s - loss: 0.6909 - acc: 0.5267 - val_loss: 0.6925 - val_acc: 0.5183\n",
      "Epoch 17/100\n",
      " - 2s - loss: 0.6894 - acc: 0.5351 - val_loss: 0.6923 - val_acc: 0.5380\n",
      "Epoch 18/100\n",
      " - 2s - loss: 0.6895 - acc: 0.5348 - val_loss: 0.6921 - val_acc: 0.5295\n",
      "Epoch 19/100\n",
      " - 2s - loss: 0.6893 - acc: 0.5348 - val_loss: 0.6918 - val_acc: 0.5323\n",
      "Epoch 20/100\n",
      " - 2s - loss: 0.6882 - acc: 0.5409 - val_loss: 0.6914 - val_acc: 0.5370\n",
      "Epoch 21/100\n",
      " - 2s - loss: 0.6877 - acc: 0.5516 - val_loss: 0.6910 - val_acc: 0.5483\n",
      "Epoch 22/100\n",
      " - 2s - loss: 0.6859 - acc: 0.5594 - val_loss: 0.6903 - val_acc: 0.5586\n",
      "Epoch 23/100\n",
      " - 2s - loss: 0.6855 - acc: 0.5606 - val_loss: 0.6895 - val_acc: 0.5633\n",
      "Epoch 24/100\n",
      " - 2s - loss: 0.6838 - acc: 0.5661 - val_loss: 0.6885 - val_acc: 0.5867\n",
      "Epoch 25/100\n",
      " - 2s - loss: 0.6825 - acc: 0.5663 - val_loss: 0.6871 - val_acc: 0.6007\n",
      "Epoch 26/100\n",
      " - 2s - loss: 0.6796 - acc: 0.5816 - val_loss: 0.6854 - val_acc: 0.6167\n",
      "Epoch 27/100\n",
      " - 2s - loss: 0.6764 - acc: 0.5944 - val_loss: 0.6829 - val_acc: 0.6232\n",
      "Epoch 28/100\n",
      " - 2s - loss: 0.6736 - acc: 0.5989 - val_loss: 0.6799 - val_acc: 0.6439\n",
      "Epoch 29/100\n",
      " - 2s - loss: 0.6692 - acc: 0.6134 - val_loss: 0.6761 - val_acc: 0.6598\n",
      "Epoch 30/100\n",
      " - 2s - loss: 0.6651 - acc: 0.6145 - val_loss: 0.6710 - val_acc: 0.6635\n",
      "Epoch 31/100\n",
      " - 2s - loss: 0.6573 - acc: 0.6256 - val_loss: 0.6648 - val_acc: 0.6748\n",
      "Epoch 32/100\n",
      " - 2s - loss: 0.6527 - acc: 0.6322 - val_loss: 0.6579 - val_acc: 0.6945\n",
      "Epoch 33/100\n",
      " - 2s - loss: 0.6441 - acc: 0.6513 - val_loss: 0.6491 - val_acc: 0.6982\n",
      "Epoch 34/100\n",
      " - 2s - loss: 0.6333 - acc: 0.6632 - val_loss: 0.6392 - val_acc: 0.7029\n",
      "Epoch 35/100\n",
      " - 2s - loss: 0.6203 - acc: 0.6718 - val_loss: 0.6277 - val_acc: 0.7179\n",
      "Epoch 36/100\n",
      " - 2s - loss: 0.6060 - acc: 0.6915 - val_loss: 0.6150 - val_acc: 0.7216\n",
      "Epoch 37/100\n",
      " - 2s - loss: 0.5897 - acc: 0.7053 - val_loss: 0.6016 - val_acc: 0.7338\n",
      "Epoch 38/100\n",
      " - 2s - loss: 0.5754 - acc: 0.7158 - val_loss: 0.5884 - val_acc: 0.7413\n",
      "Epoch 39/100\n",
      " - 2s - loss: 0.5575 - acc: 0.7240 - val_loss: 0.5750 - val_acc: 0.7507\n",
      "Epoch 40/100\n",
      " - 2s - loss: 0.5417 - acc: 0.7401 - val_loss: 0.5625 - val_acc: 0.7554\n",
      "Epoch 41/100\n",
      " - 2s - loss: 0.5212 - acc: 0.7560 - val_loss: 0.5498 - val_acc: 0.7657\n",
      "Epoch 42/100\n",
      " - 2s - loss: 0.5083 - acc: 0.7606 - val_loss: 0.5390 - val_acc: 0.7685\n",
      "Epoch 43/100\n",
      " - 2s - loss: 0.4885 - acc: 0.7738 - val_loss: 0.5290 - val_acc: 0.7591\n",
      "Epoch 44/100\n",
      " - 2s - loss: 0.4676 - acc: 0.7893 - val_loss: 0.5209 - val_acc: 0.7741\n",
      "Epoch 45/100\n",
      " - 2s - loss: 0.4561 - acc: 0.7921 - val_loss: 0.5125 - val_acc: 0.7760\n",
      "Epoch 46/100\n",
      " - 2s - loss: 0.4415 - acc: 0.8003 - val_loss: 0.5063 - val_acc: 0.7760\n",
      "Epoch 47/100\n",
      " - 2s - loss: 0.4305 - acc: 0.8097 - val_loss: 0.4999 - val_acc: 0.7760\n",
      "Epoch 48/100\n",
      " - 2s - loss: 0.4147 - acc: 0.8171 - val_loss: 0.4950 - val_acc: 0.7760\n",
      "Epoch 49/100\n",
      " - 2s - loss: 0.4026 - acc: 0.8237 - val_loss: 0.4913 - val_acc: 0.7844\n",
      "Epoch 50/100\n",
      " - 2s - loss: 0.3879 - acc: 0.8313 - val_loss: 0.4874 - val_acc: 0.7807\n",
      "Epoch 51/100\n",
      " - 2s - loss: 0.3781 - acc: 0.8348 - val_loss: 0.4843 - val_acc: 0.7873\n",
      "Epoch 52/100\n",
      " - 2s - loss: 0.3691 - acc: 0.8410 - val_loss: 0.4816 - val_acc: 0.7854\n",
      "Epoch 53/100\n",
      " - 2s - loss: 0.3615 - acc: 0.8437 - val_loss: 0.4802 - val_acc: 0.7854\n",
      "Epoch 54/100\n",
      " - 2s - loss: 0.3474 - acc: 0.8548 - val_loss: 0.4787 - val_acc: 0.7844\n",
      "Epoch 55/100\n",
      " - 2s - loss: 0.3334 - acc: 0.8608 - val_loss: 0.4774 - val_acc: 0.7882\n",
      "Epoch 56/100\n",
      " - 3s - loss: 0.3321 - acc: 0.8609 - val_loss: 0.4759 - val_acc: 0.7882\n",
      "Epoch 57/100\n",
      " - 2s - loss: 0.3260 - acc: 0.8667 - val_loss: 0.4756 - val_acc: 0.7910\n",
      "Epoch 58/100\n",
      " - 2s - loss: 0.3072 - acc: 0.8729 - val_loss: 0.4753 - val_acc: 0.7957\n",
      "Epoch 59/100\n",
      " - 2s - loss: 0.3073 - acc: 0.8730 - val_loss: 0.4758 - val_acc: 0.7976\n",
      "Epoch 60/100\n",
      " - 2s - loss: 0.2942 - acc: 0.8796 - val_loss: 0.4769 - val_acc: 0.8004\n",
      "Epoch 61/100\n",
      " - 2s - loss: 0.2778 - acc: 0.8842 - val_loss: 0.4781 - val_acc: 0.7985\n",
      "Epoch 62/100\n",
      " - 2s - loss: 0.2712 - acc: 0.8889 - val_loss: 0.4796 - val_acc: 0.7985\n",
      "Epoch 63/100\n",
      " - 2s - loss: 0.2618 - acc: 0.8941 - val_loss: 0.4809 - val_acc: 0.7985\n",
      "Epoch 64/100\n",
      " - 2s - loss: 0.2534 - acc: 0.8971 - val_loss: 0.4826 - val_acc: 0.8051\n",
      "Epoch 65/100\n",
      " - 2s - loss: 0.2577 - acc: 0.8986 - val_loss: 0.4830 - val_acc: 0.7976\n",
      "Epoch 66/100\n",
      " - 2s - loss: 0.2508 - acc: 0.9004 - val_loss: 0.4852 - val_acc: 0.7957\n",
      "Epoch 67/100\n",
      " - 2s - loss: 0.2443 - acc: 0.8997 - val_loss: 0.4888 - val_acc: 0.8022\n",
      "Epoch 68/100\n",
      " - 2s - loss: 0.2383 - acc: 0.9053 - val_loss: 0.4896 - val_acc: 0.8032\n",
      "Epoch 69/100\n",
      " - 2s - loss: 0.2370 - acc: 0.9030 - val_loss: 0.4912 - val_acc: 0.8022\n",
      "Epoch 70/100\n",
      " - 2s - loss: 0.2257 - acc: 0.9121 - val_loss: 0.4935 - val_acc: 0.7994\n",
      "Epoch 71/100\n",
      " - 2s - loss: 0.2242 - acc: 0.9085 - val_loss: 0.4956 - val_acc: 0.8013\n",
      "Epoch 72/100\n",
      " - 2s - loss: 0.2130 - acc: 0.9172 - val_loss: 0.4989 - val_acc: 0.8022\n",
      "Epoch 73/100\n",
      " - 2s - loss: 0.2066 - acc: 0.9181 - val_loss: 0.5021 - val_acc: 0.7994\n",
      "Epoch 74/100\n",
      " - 2s - loss: 0.1988 - acc: 0.9196 - val_loss: 0.5046 - val_acc: 0.7985\n",
      "Epoch 75/100\n",
      " - 2s - loss: 0.2016 - acc: 0.9216 - val_loss: 0.5089 - val_acc: 0.8013\n",
      "Epoch 76/100\n",
      " - 2s - loss: 0.1928 - acc: 0.9266 - val_loss: 0.5143 - val_acc: 0.7994\n",
      "Epoch 77/100\n",
      " - 2s - loss: 0.1846 - acc: 0.9281 - val_loss: 0.5168 - val_acc: 0.7948\n",
      "Epoch 78/100\n",
      " - 2s - loss: 0.1892 - acc: 0.9270 - val_loss: 0.5215 - val_acc: 0.7985\n",
      "Epoch 79/100\n",
      " - 2s - loss: 0.1792 - acc: 0.9300 - val_loss: 0.5254 - val_acc: 0.7966\n",
      "Epoch 80/100\n",
      " - 2s - loss: 0.1791 - acc: 0.9290 - val_loss: 0.5273 - val_acc: 0.7957\n",
      "Epoch 81/100\n",
      " - 2s - loss: 0.1781 - acc: 0.9291 - val_loss: 0.5328 - val_acc: 0.7938\n",
      "Epoch 82/100\n",
      " - 2s - loss: 0.1722 - acc: 0.9309 - val_loss: 0.5361 - val_acc: 0.7957\n",
      "Epoch 83/100\n",
      " - 2s - loss: 0.1708 - acc: 0.9334 - val_loss: 0.5385 - val_acc: 0.7948\n",
      "Epoch 84/100\n",
      " - 2s - loss: 0.1617 - acc: 0.9385 - val_loss: 0.5419 - val_acc: 0.7976\n",
      "Epoch 85/100\n",
      " - 2s - loss: 0.1621 - acc: 0.9348 - val_loss: 0.5463 - val_acc: 0.7994\n",
      "Epoch 86/100\n",
      " - 2s - loss: 0.1519 - acc: 0.9438 - val_loss: 0.5529 - val_acc: 0.8013\n",
      "Epoch 87/100\n",
      " - 2s - loss: 0.1530 - acc: 0.9402 - val_loss: 0.5563 - val_acc: 0.7985\n",
      "Epoch 88/100\n",
      " - 2s - loss: 0.1468 - acc: 0.9461 - val_loss: 0.5622 - val_acc: 0.7985\n",
      "Epoch 89/100\n",
      " - 2s - loss: 0.1449 - acc: 0.9425 - val_loss: 0.5664 - val_acc: 0.7976\n",
      "Epoch 90/100\n",
      " - 2s - loss: 0.1456 - acc: 0.9434 - val_loss: 0.5732 - val_acc: 0.7929\n",
      "Epoch 91/100\n",
      " - 2s - loss: 0.1370 - acc: 0.9490 - val_loss: 0.5762 - val_acc: 0.7901\n",
      "Epoch 92/100\n",
      " - 2s - loss: 0.1352 - acc: 0.9478 - val_loss: 0.5840 - val_acc: 0.7910\n",
      "Epoch 93/100\n",
      " - 2s - loss: 0.1329 - acc: 0.9490 - val_loss: 0.5878 - val_acc: 0.7929\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 94/100\n",
      " - 2s - loss: 0.1308 - acc: 0.9499 - val_loss: 0.5931 - val_acc: 0.7919\n",
      "Epoch 95/100\n",
      " - 2s - loss: 0.1241 - acc: 0.9531 - val_loss: 0.6024 - val_acc: 0.7929\n",
      "Epoch 96/100\n",
      " - 2s - loss: 0.1241 - acc: 0.9530 - val_loss: 0.6084 - val_acc: 0.7919\n",
      "Epoch 97/100\n",
      " - 2s - loss: 0.1276 - acc: 0.9517 - val_loss: 0.6093 - val_acc: 0.7938\n",
      "Epoch 98/100\n",
      " - 2s - loss: 0.1230 - acc: 0.9541 - val_loss: 0.6133 - val_acc: 0.7938\n",
      "Epoch 99/100\n",
      " - 2s - loss: 0.1169 - acc: 0.9573 - val_loss: 0.6165 - val_acc: 0.7938\n",
      "Epoch 100/100\n",
      " - 2s - loss: 0.1074 - acc: 0.9616 - val_loss: 0.6222 - val_acc: 0.7966\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x26d40d4ecf8>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Train the model\n",
    "model.fit(x_train, y_train, batch_size=batch_size, epochs=num_epochs,\n",
    "          validation_data=(x_test, y_test), verbose=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "o1MIEF-A8wzZ"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "x1vVUc-S8w7k"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "BRcPazwc8w-p"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "name": "Untitled0.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
